<?php

	/**
	 * 获取网站参数
	 */
	function getSiteInfo($field){
		$Fields = M('Fields');
		if(S('siteInfo'.$field)){
			$value = S('siteInfo'.$field);
		}else{
			$value = $Fields->where('flag=1 and field = "'.$field.'"')->getField('value');
			S('siteInfo'.$field,$value);
		}
		return $value;
	}
	
	/**
	 * 获取分类
	 * 缓存到cookie
	 */
	function getProductType(){
		$Subtype = M('Subtype');$Type = M('Type');
		if(S('C_PRODUCT_TYPE')){
			$tData = S('C_PRODUCT_TYPE');
		}else{
			$tData['typeList'] = $Type->where('reserve = 1 and flag = 1')->field('id,type_name as typeName,icon')->limit(7)->order('seq asc')->select();
			$field = 'id,type_id as typeId,subtype_code as subTypeCode,name,photo,spec,price,sell_num as sellNum,seq';
			foreach ($tData['typeList'] as $tk=>$tv){
				$sData = $Subtype->where('flag = 1 and parent_id = '.$tv['id'])->field('parent_id as typeId,subtype_code as subTypeCode,subtype_name as subTypeName,icon')->order('seq asc')->select();
				$tData['typeList'][$tk]['subTypeList'] = $sData;
			}
			$tData = json_encode($tData);
			S('C_PRODUCT_TYPE',$tData,3600);
		}
		return $tData;
	}

	/**
	 * 获取热搜关键字
	 * 缓存到cookie
	 */
	function getHotKeyword(){
		$HotKeyword = M('HotKeyword');
		if(S('C_PRODUCT_HOT_KEYWORD')){
			$tData = S('C_PRODUCT_HOT_KEYWORD');
		}else{
			$tData = $HotKeyword->where('flag = 1')->order('num desc')->limit(10)->field('keyword')->select();
			$tData = json_encode($tData);
			S('C_PRODUCT_HOT_KEYWORD',$tData,3600);
		}
		return $tData;
	}